package com.doctor.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import com.doctor.entity.Linkman;
import com.doctor.exception.ServiceException;
import com.doctor.repository.LinkmanRepository;
import com.doctor.service.LinkmanService;

@Service
@Transactional
public class LinkmanServiceImpl implements LinkmanService {

    @Resource
    private LinkmanRepository linkmanRepository;
    
    @Override
    public Page<Linkman> findAll(PageRequest pageRequest) {
        return linkmanRepository.findAll(pageRequest);
    }

    @Override
    public Linkman findById(Long id) {
        return linkmanRepository.findOne(id);
    }

    @Override
    public void saveOrUpdate(Linkman linkman) {
        if(linkman == null){
            throw new ServiceException("联系人不能为空");
        }
        linkman.setCreateAt(new Date());
        linkmanRepository.saveAndFlush(linkman);
    }

    @Override
    public void delete(Long id) {
        linkmanRepository.delete(id);
    }

    @Override
    public List<Linkman> findAllMan() {
        return linkmanRepository.findAll();
    }

}
